const ffmpeg = require("fluent-ffmpeg");

// 输入视频文件路径
const inputFilePath = "./public/videos/小当家.mp4";
// 输出视频文件路径
const outputFilePath = "./public/videos/小当家-2秒.mp4";

// 使用 fluent-ffmpeg 截取视频前 2 秒
ffmpeg(inputFilePath)
  .outputOptions("-t 2") // 截取前 2 秒
  .on("start", (commandLine) => {
    console.log("Spawned ffmpeg with command: " + commandLine);
  })
  .on("error", (err) => {
    console.log("An error occurred: " + err.message);
  })
  .on("end", () => {
    console.log("Processing finished !");
  })
  .saveToFile(outputFilePath); // 保存到指定路径
